package userredis

import (
	"context"

	"github.com/redis/go-redis/v9"
)

type CusRedis struct {
	RedisDB *redis.Client
}

func Connect() *CusRedis {
	if CusRedisClient.RedisDB == nil {
		CusRedisClient.RedisDB = redis.NewClient(&redis.Options{
			Addr:     "localhost:6379",
			Password: "", // 没有密码，默认值
			DB:       0,  // 默认DB 0
		})
	}
	_, err := CusRedisClient.RedisDB.Ping(context.Background()).Result()
	if err != nil {
		panic(err.Error())
	}
	return CusRedisClient
}

var CusRedisClient = &CusRedis{}
